def is_prime(n):
    if n <= 1:
        return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0:
            return False
    return True
def closest_prime(num):
    if is_prime(num):
        return num
    offset = 1
    while True:
        if is_prime(num - offset):
            return num - offset
        if is_prime(num + offset):
            return num + offset
        offset += 1
words_to_numbers = {
    'zero': 0, 'one': 1, 'two': 2, 'three': 3, 'four': 4,
    'five': 5, 'six': 6, 'seven': 7, 'eight': 8, 'nine': 9
}
def words_to_num(words):
    try:
        return words_to_numbers[words[0]] * 100 + words_to_numbers[words[1]] * 10 + words_to_numbers[words[2]]
    except KeyError:
        return None
input_words = input().strip().split()
if len(input_words) == 3:
    number = words_to_num(input_words)
    if number is not None:
        print(closest_prime(number))
    else:
        print("Wrong input")
else:
    print("Wrong input")
